﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WS.EKA.Business.Model;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace WS.EKA.UI.Business
{
    internal class TodayStatusIncident : ReportBase<List<TodayStatusIncidentForUI>>
    {
        public override WebSocketClientType Key
        {
            get
            {
                return WebSocketClientType.Incident_TodayStatus;
            }
        }

        public override string GetJsonString(object parameter)
        {
            var obj = parameter as ReportParameter<List<TodayStatusIncidentForUI>>;
            JArray array = new JArray();
            foreach (var item in obj.Data)
            {
                JArray j = new JArray();
                j.Add(TransferStatusName(item.Category));
                j.Add(item.Count);
                array.Add(j);
            }
            string str = JsonConvert.SerializeObject(array);
            return "[" + str + "]";
        }

        private string TransferStatusName(string name)
        {
            IncidentStatus status;
            Enum.TryParse<IncidentStatus>(name, out status);
            switch (status)
            {
                case IncidentStatus.Active:
                    return "处理中";
                case IncidentStatus.Logged:
                    return "已记录";
                case IncidentStatus.Assigned:
                    return "已分派";
                case IncidentStatus.Resolved:
                    return "已解决";
                case IncidentStatus.Closed:
                    return "已关闭";
                case IncidentStatus.Cancelled:
                    return "已取消";
                case IncidentStatus.Pending:
                    return "暂停";
                case IncidentStatus.Reopen:
                    return "已重开";
                default:
                    return "未知";
            }
        }
    }
}
